package com.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Account{
    private double balance;
    private final Lock lock = new ReentrantLock();
    Account(){
        balance =100000;
    }
    public void drawBalance(){
        lock.lock();
        if(balance > 0){
            System.out.println(Thread.currentThread() + "正在取钱");
            balance -= 100000;
            System.out.println(Thread.currentThread() + "取钱成功");
        }
        else{
            System.out.println(Thread.currentThread().getName() + "取钱失败，余额不足");
        }
        lock.unlock();
    }

}